package erfgame.frontend.desktop.view.terrain.iso.interaction;

import java.util.List;

import erfgame.core.Point3D;
import erfgame.core.entity.Entity;
import erfgame.core.entity.State;
import erfgame.core.graphics.renderer.RendererContext;
import erfgame.core.graphics.renderer.chain.RendererChain;
import erfgame.core.path.PathCalculator;
import erfgame.core.world.WorldContext;
import erfgame.core.world.WorldDAOManager;

import erfgame.frontend.desktop.view.terrain.iso.EntitySelection;

public class WalkEntityInteractionFactory 
	implements EntityInteractionFactory {

	private WorldContext worldContext;
	private long duration;
	private State walkState;
	private PathCalculator pathCalculator;
	private EntitySelection entitySelection;
	private WorldDAOManager worldDAOManager;
	private RendererContext rendererContext;
	
	public WalkEntityInteractionFactory( 
			WorldContext worldContext, 
			long duration,
			State walkState,
			PathCalculator pathCalculator,
			EntitySelection entitySelection, 
			WorldDAOManager worldDAOManager,
			RendererContext rendererContext
	) {
		this.worldContext = worldContext;
		this.duration = duration;
		this.walkState = walkState;
		this.pathCalculator = pathCalculator;
		this.entitySelection = entitySelection;
		this.worldDAOManager = worldDAOManager;
		this.rendererContext = rendererContext;
	}
	
	public Interaction createInteraction(Entity entity, Point3D terrain) {
		
		if( terrain != null ) {
			List<RendererChain> renderers = entitySelection.getSelected();
			if( renderers != null && renderers.size() > 0 ) {
				Entity toWalk = renderers.get(0).getHead().getEntity();
				if( toWalk != null ) {
					return new WalkInteraction(
							toWalk, 
							terrain, 
							worldContext, 
							duration, 
							walkState,
							pathCalculator,
							worldDAOManager,
							rendererContext
					);
				} else {
					return null;
				}
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

}
